package edu.biwu.servlet;/**
 * @author 王俊彪
 * @version 1.0
 */

import edu.biwu.bean.User;
import edu.biwu.utils.JDBCUtils;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.sql.SQLException;

@WebServlet("/login")
public class LoginServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        System.out.println(this.getServletContext());

        String username = request.getParameter("username");
        String password = request.getParameter("password");
        System.out.println(username + " , "+password);
        QueryRunner qr = new QueryRunner(JDBCUtils.getDataSource());
        try {
            Object query = qr.query("SELECT * FROM `user` WHERE username=? AND password=?",new BeanHandler<>(User.class), username, password);
            if (query!=null){
                System.out.println("找到了");
            }else {
                System.out.println("没有找到");
            }
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }

    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }
}
